<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="厂站信息编号" prop="plantStationsId">
        <el-input
          v-model="queryParams.plantStationsId"
          placeholder="请输入厂站信息编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="时间维度" prop="timeDimension">
        <el-input
          v-model="queryParams.timeDimension"
          placeholder="请输入时间维度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="统计年份" prop="statisticYear">
        <el-input
          v-model="queryParams.statisticYear"
          placeholder="请输入统计年份"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="统计月份" prop="statisticMonth">
        <el-input
          v-model="queryParams.statisticMonth"
          placeholder="请输入统计月份"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="统计日期" prop="statisticDay">
        <el-input
          v-model="queryParams.statisticDay"
          placeholder="请输入统计日期"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电量" prop="electricityConsumption">
        <el-input
          v-model="queryParams.electricityConsumption"
          placeholder="请输入电量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电费" prop="electricityCost">
        <el-input
          v-model="queryParams.electricityCost"
          placeholder="请输入电费"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="泵组 ID" prop="pumpGroupId">
        <el-input
          v-model="queryParams.pumpGroupId"
          placeholder="请输入泵组 ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="每电耗数据" prop="unitElectricityConsumption">
        <el-input
          v-model="queryParams.unitElectricityConsumption"
          placeholder="请输入每电耗数据"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出口压力" prop="outletPressure">
        <el-input
          v-model="queryParams.outletPressure"
          placeholder="请输入出口压力"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出口流量" prop="outletFlow">
        <el-input
          v-model="queryParams.outletFlow"
          placeholder="请输入出口流量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建人" prop="creator">
        <el-input
          v-model="queryParams.creator"
          placeholder="请输入创建人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新人" prop="updater">
        <el-input
          v-model="queryParams.updater"
          placeholder="请输入更新人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预期节能效果" prop="expectedEnergySavingEffect">
        <el-input
          v-model="queryParams.expectedEnergySavingEffect"
          placeholder="请输入预期节能效果"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:dispatchEnergyConsumption:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:dispatchEnergyConsumption:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:dispatchEnergyConsumption:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:dispatchEnergyConsumption:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dispatchEnergyConsumptionList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="能耗分析编号" align="center" prop="energyConsumptionId" />
      <el-table-column label="厂站信息编号" align="center" prop="plantStationsId" />
      <el-table-column label="时间维度" align="center" prop="timeDimension" />
      <el-table-column label="统计年份" align="center" prop="statisticYear" />
      <el-table-column label="统计月份" align="center" prop="statisticMonth" />
      <el-table-column label="统计日期" align="center" prop="statisticDay" />
      <el-table-column label="电量" align="center" prop="electricityConsumption" />
      <el-table-column label="电费" align="center" prop="electricityCost" />
      <el-table-column label="泵组 ID" align="center" prop="pumpGroupId" />
      <el-table-column label="每电耗数据" align="center" prop="unitElectricityConsumption" />
      <el-table-column label="出口压力" align="center" prop="outletPressure" />
      <el-table-column label="出口流量" align="center" prop="outletFlow" />
      <el-table-column label="优化开停泵方案建议" align="center" prop="optimizationSuggestion" />
      <el-table-column label="创建人" align="center" prop="creator" />
      <el-table-column label="更新人" align="center" prop="updater" />
      <el-table-column label="预期节能效果" align="center" prop="expectedEnergySavingEffect" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:dispatchEnergyConsumption:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:dispatchEnergyConsumption:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改能耗分析对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="厂站信息编号" prop="plantStationsId">
          <el-input v-model="form.plantStationsId" placeholder="请输入厂站信息编号" />
        </el-form-item>
        <el-form-item label="时间维度" prop="timeDimension">
          <el-input v-model="form.timeDimension" placeholder="请输入时间维度" />
        </el-form-item>
        <el-form-item label="统计年份" prop="statisticYear">
          <el-input v-model="form.statisticYear" placeholder="请输入统计年份" />
        </el-form-item>
        <el-form-item label="统计月份" prop="statisticMonth">
          <el-input v-model="form.statisticMonth" placeholder="请输入统计月份" />
        </el-form-item>
        <el-form-item label="统计日期" prop="statisticDay">
          <el-input v-model="form.statisticDay" placeholder="请输入统计日期" />
        </el-form-item>
        <el-form-item label="电量" prop="electricityConsumption">
          <el-input v-model="form.electricityConsumption" placeholder="请输入电量" />
        </el-form-item>
        <el-form-item label="电费" prop="electricityCost">
          <el-input v-model="form.electricityCost" placeholder="请输入电费" />
        </el-form-item>
        <el-form-item label="泵组 ID" prop="pumpGroupId">
          <el-input v-model="form.pumpGroupId" placeholder="请输入泵组 ID" />
        </el-form-item>
        <el-form-item label="每电耗数据" prop="unitElectricityConsumption">
          <el-input v-model="form.unitElectricityConsumption" placeholder="请输入每电耗数据" />
        </el-form-item>
        <el-form-item label="出口压力" prop="outletPressure">
          <el-input v-model="form.outletPressure" placeholder="请输入出口压力" />
        </el-form-item>
        <el-form-item label="出口流量" prop="outletFlow">
          <el-input v-model="form.outletFlow" placeholder="请输入出口流量" />
        </el-form-item>
        <el-form-item label="优化开停泵方案建议" prop="optimizationSuggestion">
          <el-input v-model="form.optimizationSuggestion" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="创建人" prop="creator">
          <el-input v-model="form.creator" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="更新人" prop="updater">
          <el-input v-model="form.updater" placeholder="请输入更新人" />
        </el-form-item>
        <el-form-item label="预期节能效果" prop="expectedEnergySavingEffect">
          <el-input v-model="form.expectedEnergySavingEffect" placeholder="请输入预期节能效果" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDispatchEnergyConsumption, getDispatchEnergyConsumption, delDispatchEnergyConsumption, addDispatchEnergyConsumption, updateDispatchEnergyConsumption } from "@/api/system/dispatchEnergyConsumption";

export default {
  name: "DispatchEnergyConsumption",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 能耗分析表格数据
      dispatchEnergyConsumptionList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        plantStationsId: null,
        timeDimension: null,
        statisticYear: null,
        statisticMonth: null,
        statisticDay: null,
        electricityConsumption: null,
        electricityCost: null,
        pumpGroupId: null,
        unitElectricityConsumption: null,
        outletPressure: null,
        outletFlow: null,
        optimizationSuggestion: null,
        creator: null,
        updater: null,
        expectedEnergySavingEffect: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询能耗分析列表 */
    getList() {
      this.loading = true;
      listDispatchEnergyConsumption(this.queryParams).then(response => {
        this.dispatchEnergyConsumptionList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        energyConsumptionId: null,
        plantStationsId: null,
        timeDimension: null,
        statisticYear: null,
        statisticMonth: null,
        statisticDay: null,
        electricityConsumption: null,
        electricityCost: null,
        pumpGroupId: null,
        unitElectricityConsumption: null,
        outletPressure: null,
        outletFlow: null,
        optimizationSuggestion: null,
        createTime: null,
        creator: null,
        updater: null,
        updateTime: null,
        expectedEnergySavingEffect: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.energyConsumptionId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加能耗分析";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const energyConsumptionId = row.energyConsumptionId || this.ids
      getDispatchEnergyConsumption(energyConsumptionId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改能耗分析";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.energyConsumptionId != null) {
            updateDispatchEnergyConsumption(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDispatchEnergyConsumption(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const energyConsumptionIds = row.energyConsumptionId || this.ids;
      this.$modal.confirm('是否确认删除能耗分析编号为"' + energyConsumptionIds + '"的数据项？').then(function() {
        return delDispatchEnergyConsumption(energyConsumptionIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/dispatchEnergyConsumption/export', {
        ...this.queryParams
      }, `dispatchEnergyConsumption_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
